// pages/familydoctor/servicepackage/servicepackage.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isshow: true,
    list: [{
        id: 0,
        title: "老年人家庭医生签约服务基本包",
        price: "0.0",
        isshow: false
      },
      {
        id: 1,
        title: "老年人家庭医生签约服务基本包",
        price: "0.0",
        isshow: false
      },
      {
        id: 2,
        title: "老年人家庭医生签约服务基本包",
        price: "0.0",
        isshow: false
      },
      {
        id: 3,
        title: "老年人家庭医生签约服务基本包",
        price: "0.0",
        isshow: false
      },
      {
        id: 4,
        title: "老年人家庭医生签约服务基本包",
        price: "0.0",
        isshow: false
      },
      {
        id: 5,
        title: "老年人家庭医生签约服务基本包",
        price: "0.0",
        isshow: false
      },
    ],
    check: false,
    index: "",
  },
  choose: function(e) {
    var that = this
    var index = e.currentTarget.dataset.index
    var list = that.data.fwlist;
    list[index].isshow = !list[index].isshow
    that.setData({
      fwlist: list,
      index: index
    })
    var sum = 0;
    for (var i = 0; i < list.length; i++) {
      if (list[i].isshow == true) {

        sum += parseFloat(list[i].fw_money)
      }
    }
    sum = parseFloat(sum.toFixed(2))
    that.setData({
      sum: sum
    })
  },
  // checkbtn: function() {
  //   this.setData({
  //     check: !this.data.check
  //   })
  //   console.log(this.data.check)
  // },
  step: function() {
    var that = this
    var index = that.data.index
    var list = that.data.fwlist;
    var t_id = that.data.t_id
    var sid = that.data.sid
    var key = that.data.key
    var name = that.data.name
    var j_id = that.data.j_id
    var names = that.data.names
    var money = that.data.sum
    var teamname = that.data.teamname
    var ifhz = that.data.ifhz
    var hzsfz = that.data.hzsfz
    var zid = that.data.zid
    if (index === "") {
      wx.showToast({
        title: '请选择签约服务包',
        icon: "none"
      })
    } else {
      var list = that.data.fwlist
      var arr = []
      for (var i = 0; i < list.length; i++) {
        if (list[i].isshow == true) {
          arr.push(list[i])
        }
      }
      var zhichengArr = []
      for (var i = 0, len = arr.length; i < len; i++) {
        if (arr[i].ff_id) {
          zhichengArr.push(arr[i].ff_id)
        }
      }
      var arr1 = JSON.stringify(zhichengArr)
      wx.navigateTo({
        url: '/hyb_yl/doctor/pages/familydoctor/sign/sign?item=' + arr1 + '&t_id=' + t_id + '&sid=' + sid + '&key=' + key + '&name=' + name + '&j_id=' + j_id + '&names=' + names + '&money=' + money + '&teamname=' + teamname + '&ifhz=' + ifhz + '&hzsfz=' + hzsfz + '&zid=' + zid,
      })
    }
  },
  server: function(e) {
    var that = this
    var ff_id = e.currentTarget.dataset.ff_id
    var title = e.currentTarget.dataset.title
    wx.navigateTo({
      url: '/hyb_yl/doctor/pages/familydoctor/signing/signing?ff_id=' + ff_id + '&title=' + title,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    var that = this
    var bgc = wx.getStorageSync('color')
    var teamname = options.teamname
    var t_id = options.t_id
    var sid = options.sid
    var key = options.key
    var name = options.name
    var j_id = options.j_id
    var hzsfz = options.hzsfz
    var ifhz = options.ifhz
    var names = options.names
    var zid = options.zid
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var arr = JSON.parse(options.arr)
    console.log(arr)
    that.setData({
      bgc: bgc,
      t_id: t_id,
      key: key,
      sid: sid,
      name: name,
      j_id: j_id,
      names: names,
      teamname: teamname,
      hzsfz: hzsfz,
      ifhz: ifhz,
      zid: zid
    })
    app.util.request({
      'url': 'entry/wxapp/Office.allinfo',
      data: {
        arr: arr,
      },
      success(res) {
        var list = res.data
        for (var i = 0; i < list.length; i++) {
          list[i].isshow = false
        }
        that.setData({
          fwlist: list,

        })
        console.log(list)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

})